package com.wuwei.business.service.impl;

import com.wuwei.framework.config.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.wuwei.business.mapper.BusAttachmentMapper;
import com.wuwei.business.domain.BusAttachment;
import com.wuwei.business.service.BusAttachmentService;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 内容: SSM
 * 作者: weishao
 */
@Service
public class BusAttachmentServiceImpl implements BusAttachmentService{

    @Resource
    private BusAttachmentMapper busAttachmentMapper;
    @Autowired
    private ServerConfig serverConfig;

    @Override
    public int deleteByPrimaryKey(Integer fileId) {
        return busAttachmentMapper.deleteByPrimaryKey(fileId);
    }

    @Override
    public int insert(BusAttachment record) {
        return busAttachmentMapper.insert(record);
    }

    @Override
    public int insertSelective(BusAttachment record) {
        return busAttachmentMapper.insertSelective(record);
    }

    @Override
    public BusAttachment selectByPrimaryKey(Integer fileId) {
        return busAttachmentMapper.selectByPrimaryKey(fileId);
    }

    @Override
    public int updateByPrimaryKeySelective(BusAttachment record) {
        return busAttachmentMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(BusAttachment record) {
        return busAttachmentMapper.updateByPrimaryKey(record);
    }

    /**
     * 根据车牌号查询图片
     * @param carNumber 车牌号
     * @return
     */
    @Override
    public List<String> selectCarImags(String carNumber) {
        List<String> imgByCarNum=busAttachmentMapper.selectImgByCarNum(carNumber);
        if (ObjectUtils.isEmpty(imgByCarNum)){
            throw new IllegalArgumentException("该车辆暂时无图");
        }
        // 这个路径是没有项目的ip和端口的
        // 这里我们去获取当前项目的ip和端口
        String url = serverConfig.getUrl();
            return imgByCarNum.stream().map(imgs->url+imgs).collect(Collectors.toList());
    }
}
